﻿using System;
using System.Data;
using System.Data.SqlClient;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace CNotebook
{
    public class TaxManager:ConnectionManager
    {
        public DataTable GetTaxCodes()
        {
            SqlCommand oCommand = new SqlCommand();
            SqlDataAdapter oAdapter = new SqlDataAdapter();

            oCommand.Connection = this.Connection;
            oCommand.CommandText = "SELECT * FROM TAXCODE";

            oAdapter.SelectCommand = oCommand;

            DataSet ds = new DataSet();

            oAdapter.Fill(ds);

            return ds.Tables[0];
        }

        public double GetTaxRate(string sTaxCode)
        {
            SqlCommand oCommand = new SqlCommand();
            SqlDataAdapter oAdapter = new SqlDataAdapter();

            oCommand.Connection = this.Connection;
            oCommand.CommandText = "SELECT * FROM TAXCODE WHERE Code=@Code";
            oCommand.Parameters.Add(new SqlParameter("@Code", sTaxCode));

            oAdapter.SelectCommand = oCommand;

            DataSet ds = new DataSet();

            oAdapter.Fill(ds);
            string sValue = ds.Tables[0].Rows[0][1].ToString();

            return Convert.ToDouble(sValue);
        }

        public double GetVATRate(string sTaxCode)
        {
            SqlCommand oCommand = new SqlCommand();
            SqlDataAdapter oAdapter = new SqlDataAdapter();

            oCommand.Connection = this.Connection;
            oCommand.CommandText = "SELECT * FROM TAXCODE WHERE Dscription=@Code";
            oCommand.Parameters.Add(new SqlParameter("@Code", sTaxCode));

            oAdapter.SelectCommand = oCommand;

            DataSet ds = new DataSet();

            oAdapter.Fill(ds);
            string sValue = ds.Tables[0].Rows[0]["Rate"].ToString();

            return Convert.ToDouble(sValue);
        }

        public string IsInclusive(string sTaxCode)
        {
            SqlCommand oCommand = new SqlCommand();
            SqlDataAdapter oAdapter = new SqlDataAdapter();

            oCommand.Connection = this.Connection;
            oCommand.CommandText = "SELECT * FROM TAXCODE WHERE Dscription=@Code";
            oCommand.Parameters.Add(new SqlParameter("@Code", sTaxCode));

            oAdapter.SelectCommand = oCommand;

            DataSet ds = new DataSet();

            oAdapter.Fill(ds);
            string sValue = ds.Tables[0].Rows[0]["IsInclusive"].ToString();

            return sValue;
        }
    }
}
